package com.woniuxy.woniuticket.ordermodule.utils;

import com.woniuxy.woniuticket.moviemodule.dao.CinemaScheduleDAO;
import com.woniuxy.woniuticket.ordermodule.dao.CinemaOderDAO;
import com.woniuxy.woniuticket.ordermodule.constant.OrderConstant;
import com.woniuxy.woniuticket.pojo.CinemaOder;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;

/**
 * Created by Wu xianbo on 2019/6/2
 */
@Component
public class CompareTimeUtil {

    @Resource
    private CinemaOderDAO cinemaOderDAO;    //订单dao

    @Resource
    private CinemaScheduleDAO cinemaScheduleDAO;  //排片信息dao


    //校验当前订单对应票的开始时间和当前时间的大小关系
    public Boolean compareScheduleTime(CinemaOder cinemaOder){
        //排片id
        Integer schedule_id = cinemaOderDAO.selectByPrimaryKey(cinemaOder.getOrdernum()).getScheduleId();
        //原影片开始时间
        Date begintime = cinemaScheduleDAO.selectByPrimaryKey(schedule_id).getBegintime();
        //当前时间
        Date nowTime = new Date();
        System.out.println(begintime);
        System.out.println(nowTime);
        if((begintime.getTime()-nowTime.getTime())>(30*60*1000L)){
            //可以改签
            System.out.println("时间上可以改签或者退票");
            return true;
        }else{
            //不可以改签
            System.out.println("时间上不可以改签或者退票");
            return false;
        }
    }

    //改签时校验订单状态
    public Boolean checkChangeStaus(CinemaOder cinemaOder){
        //查询当前订单号对应的订单状态
        CinemaOder result = cinemaOderDAO.selectByPrimaryKey(cinemaOder.getOrdernum());
        //支付条件下可以改签
        if(result.getOderstatus().equals(OrderConstant.OK_PAY)){
            System.out.println("当前状态可以改签");
            return true;
        }
        System.out.println("当前状态不可以改签");
        return false;
    }

    //退票时校验订单状态
    public Boolean checkReturnStaus(CinemaOder cinemaOder){
        //查询当前订单号对应的订单状态
        CinemaOder result = cinemaOderDAO.selectByPrimaryKey(cinemaOder.getOrdernum());
        //支付条件或者改签条件下可以退票
        if(result.getOderstatus().equals(OrderConstant.OK_PAY )|| result.getOderstatus().equals(OrderConstant.HAVE_CHANGEED)){
            System.out.println("当前状态可以退票");
            return true;
        }
        System.out.println("当前状态不可以退票");
        return false;
    }
}
